﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using System.Web.Http.Cors;
using XQ.Framework.io.text;
using XQ.RequestOfficeSupplies.BLL.Account;
using XQ.RequestOfficeSupplies.DAL;
using XQ.RequestOfficeSupplies.DAL.Models;
using XQ.RequestOfficeSupplies.WebAPI.Common;
using XQ.RequestOfficeSupplies.WebAPI.Filter;

namespace XQ.RequestOfficeSupplies.WebAPI.Controllers.System
{
    /// <summary>
    /// 权限操作
    /// </summary>
    [FormAuthenticationFilter]
    public class RoleController : ApiController
    {
        private readonly RoleBll _bll = new RoleBll();

        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="role"></param>
        /// <returns></returns>
        [HttpPost]
        [Route("Api/Role/Save")]
        public string Save(Sys_Roles role)
        {
            return new RoleBll().Save(role);
        }

        /// <summary>
        /// 获取角色信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        [Route("Api/Role/GetRole")]
        public Sys_Roles GetRole(int id)
        {
            return _bll.GetRole(id);
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [Route("Api/Role/Delete")]
        public string Delete(int id)
        {
            return _bll.Delete(id);
        }

        /// <summary>
        /// 批量删除
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [Route("Api/Role/DeleteByIds")]
        public bool DeleteByIds(List<int> ids)
        {
            return _bll.DeleteByIds(ids);
        }

        /// <summary>
        /// 获取列表
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [Route("Api/Role/GetList")]
        public IEnumerable<Sys_Roles> GetList()
        {
            TokenModel token = TokenHelper.GetTokenByHeaders(Request.Headers);
            return _bll.GetRoles(token);
        }

    }
}